//
// Created by Zhangwj on 2023/9/27.
//

#include "MulExpNode.h"

std::unique_ptr<MulExpNode> MulExpNode::MulExpParser(Parser &parser) {
    //MulExp → UnaryExp | MulExp ('*' | '/' | '%') UnaryExp
    //改写为 MulExp -> UnaryExp { ('*' | '/' | '%') UnaryExp } 遍历时要改成原语法树的形状
    std::unique_ptr<MulExpNode> mulExpNode = std::make_unique<MulExpNode>();
    mulExpNode->UnaryExps.push_back(UnaryExpNode::UnaryExpParser(parser));
    while (parser.getLexType(0) == LexType::MULT || parser.getLexType(0) == LexType::DIV ||
           parser.getLexType(0) == LexType::MOD) {
        mulExpNode->Ops.push_back(parser.getLexType(0));
        parser.next();
        mulExpNode->UnaryExps.push_back(UnaryExpNode::UnaryExpParser(parser));
    }
    return mulExpNode;
}
